package com.chixing.fourteen.service.impl;

import com.chixing.fourteen.pojo.ReceivingOrders;
import com.chixing.fourteen.repository.ReceivingOrderRepository;
import com.chixing.fourteen.service.ReceivingOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ReceivingOrderServiceImpl implements ReceivingOrderService {

    @Autowired
    private ReceivingOrderRepository receivingOrderRepository;

    @Override
    /**
     * 创建一个接单表
     */
    public int create(int driversId, int customerOrderId) {
        ReceivingOrders receivingOrders = new ReceivingOrders();
        receivingOrders.setDriversId(driversId);
        receivingOrders.setCustomerOrderId(customerOrderId);
        // 获取当前时间为接单时间
        receivingOrders.setReceivingOrdersGetTime(new Date());
        // 默认状态为 1，已接单未上车
        receivingOrders.setReceivingOrdersStatus(1);
        return receivingOrderRepository.insert(receivingOrders);
    }

    @Override
    /**
     * 修改订单状态，用于用户取消订单以及标明订单完成过程的各阶段
     */
    public int change(int peceivingOrderId, int status) {
        return receivingOrderRepository.updateStatus(peceivingOrderId,status);
    }

    @Override
    /**
     * 添加接到乘客的时间
     */
    public int addGetCustomerTime(int peceivingOrderId, Date getCustomerTime) {
        return receivingOrderRepository.updateGetCustomerTime(peceivingOrderId, getCustomerTime);
    }

    @Override
    /**
     * 添加订单结束的时间
     */
    public int addOverTime(int peceivingOrderId, Date overTime) {
        return receivingOrderRepository.updateOverTime(peceivingOrderId, overTime);
    }
}
